import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.*;
import org.apache.commons.httpclient.methods.*;
import java.io.*;
import java.util.*;

public class uvaSubmit {
	static final String LOGON_SITE = "acm.uva.es";
	static final int LOGON_PORT = 80;
	
    //args[0] : judge_id
    //args[1] : problem_id
    //args[2] : language ( "C", "C++", "Pascal", "Java" )
    
    public static String get_run_id(String body) {
        String[] res = new String[2];
        res = body.split("&nbsp;");
        return res[1];
    }
    
    public static String get_result(String body) {
        String[] res = new String[3];
        res = body.split("&nbsp;");
        String[] ret = new String[100];
        ret = res[2].split("[<>]");
        return ret[8];
    }
    
	public static void main(String[] args) throws Exception {
        String judge_id = new String(args[0]);
        String problem_id = new String(args[1]);
        String lang = new String(args[2]);
        
		Scanner cin = new Scanner(System.in);
		String s = new String();
		while (cin.hasNextLine())
			s += cin.nextLine() + "\n";
		
        HttpClient client = new HttpClient();
		client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);
        int status;
        
        //first, get status
//    http://acm.uva.es/archive/nuevoportal/status.php?u=...
		GetMethod get = new GetMethod("/archive/nuevoportal/status.php?u=" + judge_id);
		status = client.executeMethod(get);
        String body = new String();
        body = get.getResponseBodyAsString();
		get.releaseConnection();
        
        String run_id_old = new String();
        run_id_old = get_run_id(body);
//        System.out.println("*" + run_id_old + "*");
        
        //post data
		PostMethod post = new PostMethod("/archive/nuevoportal/mailer.php");
		NameValuePair problem = new NameValuePair("problem", problem_id);
        NameValuePair userid2 = new NameValuePair("userid", judge_id);
        NameValuePair language = new NameValuePair("language", lang);
        NameValuePair source = new NameValuePair("code", s);

		System.out.println("Sending code\n" + s);

		post.setRequestBody(new NameValuePair[] { problem, userid2, language, source });
		status = client.executeMethod(post);

		System.out.print("Status = ");
		System.out.println(status);

		post.releaseConnection();
        
        //refresh the status until judge reply
        while (true) {
            status = client.executeMethod(get);
            String body1 = new String();
            body1 = get.getResponseBodyAsString();
            get.releaseConnection();
            
            String run_id_now = new String();
            run_id_now = get_run_id(body1);

//            System.out.println("*" + run_id_now + "*");

            if (!run_id_now.equals(run_id_old)) {
                String ret = new String();
                ret = get_result(body1);
                System.out.println(ret);
                break;
            }
            Thread.sleep(1000);
        }
	}
}

